package org.kabeja.parser.dxf.filter;

import org.kabeja.parser.DXFValue;
import org.kabeja.parser.ParseException;

/**
 * @author shutao
 * @since 2022/4/25 10:56
 */
abstract class DXFStreamSectionFilter extends AbstractDXFStreamFilter {
    private static final String SECTION_START = "SECTION";
    private static final String SECTION_END = "ENDSEC";
    private static final int COMMAND_CODE = 0;
    protected boolean sectionStarts = false;
    protected String section;

    DXFStreamSectionFilter() {
    }

    @Override
    public void parseGroup(int var1, DXFValue var2) throws ParseException {
        if (var1 == COMMAND_CODE && SECTION_START.equals(var2.getValue())) {
            this.sectionStarts = true;
        } else if (this.sectionStarts) {
            this.sectionStarts = false;
            this.section = var2.getValue();
            this.sectionStart(this.section);
            this.parseSection(0, new DXFValue(SECTION_START));
            this.parseSection(var1, var2);
        } else {
            this.parseSection(var1, var2);
        }

        if (var1 == COMMAND_CODE && SECTION_END.equals(var2.getValue())) {
            this.sectionEnd(this.section);
        }

    }

    protected abstract void parseSection(int var1, DXFValue var2) throws ParseException;

    protected abstract void sectionStart(String var1) throws ParseException;

    protected abstract void sectionEnd(String var1) throws ParseException;
}
